<html xmlns:th="http://www.thymeleaf.org"
>
<head th:include="include/includebase"></head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
        <div class="panel panel-default" style="margin-top: 10px;">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <form class="form-inline" role="form" style="float: left; width: 100%;margin-left: 20px;" method="post" id="queryUser">
                    <div class="form-group">
                        <label for="userName">名字:</label>
                        <input type="text" class="form-control" name="userName" id="userName"  placeholder="请输入名字" />
                    </div>
                    <div class="form-group">
                        <label for="login">账号:</label>
                        <input type="text" class="form-control" name="login" id="login"  placeholder="请输入账号" />
                    </div>
                    <div class="form-group">
                        <label for="job">职位:</label>
                        <input type="text" class="form-control" name="job" id="job"  placeholder="请输入职位" />
                    </div>
                    <div class="form-group">
                        <button type="button" id="queryBtn" onclick="doQuery();" class="btn btn-primary">查询</button>
                    </div>
                </form>
            </div>
        </div>
        <table id="user-table" style="margin-top: -50px;">
        </table>
</div>
<script th:inline="javascript">
    $(function() {
        initTable();
        $('#user-table').bootstrapTable('hideColumn', 'id');
    });

    function doQuery(){
        $('#user-table').bootstrapTable('refresh');    //刷新表格
    }

    // 账号禁用和启用
    function userControl(state,id){
        var confirmTitle = "";
        if(state==0){
            confirmTitle = "是否禁用账户？";
        }else{
            confirmTitle = "是否启用账户？";
        }
        window.Ewin.confirm({title: '提示', message: confirmTitle, width: 500}).on(function (e) {
            if (e) {
                $.post("/user/userControl",{state:state,id:id},function(data){
                    if(data.result){
                        window.Ewin.alert({message:'操作成功!'});
                        doQuery();
                    }else{
                        window.Ewin.alert({message:'操作失败!'});
                    }
                })
            }
        });
    }

    function initTable(){
        $('#user-table').bootstrapTable({
            url:"/user/list",
            height: $(window.parent.document).find("#wrapper").height() - 252,
            width:$(window).width(),
            showColumns:true,
            formId :"queryUser",
            pagination : true,
            sortName : 'id',
            sortOrder : 'desc',
            clickToSelect: true,// 单击某一行的时候选中某一条记录
            pageSize : 13,
            toolbars:[
                {
                    text: '添加',
                    iconCls: 'glyphicon glyphicon-plus',
                    handler: function () {
                        window.Ewin.dialog({title:"添加",url:"user/addPage",gridId:"gridId",width:600,height:745})
                    }
                },
                {
                    text: '修改',
                    iconCls: 'glyphicon glyphicon-pencil',
                    handler: function () {
                        var rows = $('#user-table').bootstrapTable('getSelections');
                        if(rows.length==0||rows.length>1){
                            window.Ewin.alert({message:'请选择一条需要修改的数据!'});
                            return false;
                        }
                        window.Ewin.dialog({title:"修改",url:"user/updatePage?id="+rows[0].id,width:600,height:595});
                    }
                },
                {
                    text: '删除',
                    iconCls: 'glyphicon glyphicon-remove',
                    handler: function () {
                        var rows = $('#user-table').bootstrapTable('getSelections');
                        if(rows.length==0){
                            window.Ewin.alert({message:'请选择一条需要删除的数据!'});
                            return false;
                        }
                        window.Ewin.confirm({title:'提示',message:'是否要删除您当前所勾选的用户？',width:500}).on(function (e) {
                            if (e) {
                                $.post("user/removeBath",{json:JSON.stringify(rows)},function(e){
                                    if(e.result){
                                        window.Ewin.alert({message:e.msg});
                                        doQuery();
                                    }
                                });
                            }
                        });
                    }
                }
            ],
            columns: [
                {
                    checkbox: true
                },
                {
                    field: '',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },
                {
                    field : 'id',
                    title : '用户流水',
                    align : 'center',
                    valign : 'middle',
                    hide : false,
                    sortable : true
                },
                {
                    field : 'userName',
                    title : '用户姓名',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'login',
                    title : '账号',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'job',
                    title : '职位名称',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'address',
                    title : '用户地址',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'orgGroup.name',
                    title : '组织架构',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'state',
                    title : '账号状态',
                    align : 'center',
                    valign : 'middle',
                    sortable : true,
                    formatter: function (value, row, index) {
                        return getCodeDictText("USER_STATE",value);
                    }
                },{
                    field : 'operations',
                    title : '操作',
                    align : 'center',
                    valign : 'middle',
                    formatter: function (value, row, index) {
                        if(row.state=='1'){
                            return '<a href="#" onclick="userControl(0,'+row.id+')" >禁用</a>';
                        }else{
                            return '<a href="#" onclick="userControl(1,'+row.id+')" >启用</a>';
                        }

                    }
                }]
        });
    }


</script>
</body>
</html>